package com.skwyb.form.utils;

import lombok.extern.log4j.Log4j2;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

@Log4j2
public class PropertiesUtils {
    private static Properties properties;

    static {
        if (null == properties) {
            // 读取配置启用的配置文件名
            properties = new Properties();
            InputStream in = PropertiesUtils.class.getClassLoader().getResourceAsStream("config.properties");
            try {
                properties.load(in);
            } catch (IOException e) {
                log.error(e);
            }
        }
    }

    /**
     * 根据属性名读取值
     *
     * @param name 名称
     */
    public static String getValue(String name) {
        return properties.getProperty(name);
    }


    /**
     * 根据属性名读取int值
     *
     * @param name 名称
     */
    public static Integer getIntValue(String name) {
        return Integer.valueOf(properties.getProperty(name, "0"));
    }
}
